using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Linq;

using LDAP.Entity;

namespace LDAP.BLL
{
    public class BizSchedule
    {
		public const string ENTITY_KEY = "schedule";
		
        public static int Add(Schedule entry)
        {
            return !string.IsNullOrEmpty(Common.GetMapper(ENTITY_KEY, entry).Insert("Insert_Schedule", entry).ToString())? 1:0;
        }

        public static int Update(Schedule entry)
        {
            return Common.GetMapper(ENTITY_KEY, entry).Update("Update_Schedule", entry);
        }

        public static Schedule GetByKey(string id)
        {
            return GetAll().FirstOrDefault(l => l.Id.Equals(id, StringComparison.CurrentCultureIgnoreCase));
        }

        public static List<Schedule> GetAll()
        {
            string cacheKey = "alluser_schedule";
            if (Tools.CacheUtil.Exists(cacheKey))
                return Tools.CacheUtil.Get(cacheKey) as List<Schedule>;

            var all = Common.GetMapper(ENTITY_KEY, null).QueryForList<Schedule>("Select_Schedule", null).ToList();
            Tools.CacheUtil.Insert(cacheKey, all, 3600);
            return all;
        }

        public static int Delete(int id)
        {
           return Common.GetMapper(ENTITY_KEY, id).Delete("Delete_Schedule",id);
        }
    }
}

	